<template>
	<view v-show="showNote">
		<view class="noteCard">
			<view class="mainContent">
				<!-- 此处显示笔记内容的文本框 -->
				<!-- <text-editor :noteId="questionWithNote.id" :textContent="questionWithNote.noteContent"
					:isreadOnly="isreadOnly" @editorInput='updateEditorText'></text-editor> -->
					<textarea :id=noteId :value='questionWithNote.noteContent' :disabled='isreadOnly' 
					  @input="updateEditorText" auto-height />
			</view>
			<view class="noteTop">
				<view class="topTitle">试题内容：</view>
				<!-- <exam-question :questionWithNote="questionWithNote" :needAnalyse="false"></exam-question> -->
				<u-parse :html="questionWithNote.queContent"></u-parse>
			</view>
			<view class="bottom">
				<view class="time">
					{{questionWithNote.createTime}}
				</view>
				<view class="funcGroup" @click="checkQue">
					<u-icon class="funcBtn" name="eye"></u-icon>
					<span>试题</span>
				</view>
				<view v-if="eidtOrFinishValue=='编辑'" class="funcGroup" @click="editBtnFunc(cardIndex)">
					<u-icon class="funcBtn" name="edit-pen"></u-icon>
					<span>编辑</span>
				</view>
				<view v-else class="funcGroup" @click="finishBtnFunc(cardIndex)">
					<u-icon class="funcBtn" name="edit-pen"></u-icon>
					<span>完成</span>
				</view>
				<!-- <view class="funcGroup" @click="deleteBtnFunc(cardIndex)">
					<u-icon class="funcBtn" name="trash"></u-icon>
					<span>删除</span>
				</view> -->
			</view>

			<!-- 渲染题目详情 -->
			<u-popup v-model="showDetail" mode="center" border-radius="20">
				<view class="QuesModal">
					<scroll-view scroll-y="true" style="height: 700rpx;">
						<view>
							<exam-question :queDetail="queDetail"></exam-question>
						</view>
					</scroll-view>
				</view>
			</u-popup>
		</view>
	</view>
</template>

<script>
	import Modal from '@/components/dyw-answer/modal.vue'
	export default {
		props: {
			questionWithNote: Object,
			cardIndex: Number
		},
		components: {
			Modal
		},
		data() {
			return {
				queDetail: {},
				showDetail: false,
				isReviewed: true,
				isreadOnly: true,
				eidtOrFinishValue: '编辑',
				eidtOrFinish: true,
				showNote: true,
				editorText: ''
			}
		},
		methods: {
			deleteBtnFunc(cardIndex) {
				uni.showToast({
					title: '删除笔记成功',
					icon: 'none'
				})
				// this.$emit('deleteNote')
				this.showNote = !this.showNote
			},
			editBtnFunc(cardIndex) {
				this.isreadOnly = !this.isreadOnly
				this.eidtOrFinishValue = '完成'
			},
			finishBtnFunc() {
				this.isreadOnly = !this.isreadOnly
				this.eidtOrFinishValue = '编辑'
				this.$api.updateNote(this.questionWithNote.id, this.editorText)
					.then(res => {
						console.log('更新笔记成功', res)
					})
			},
			checkQue() {
				var that = this
				this.showDetail = !this.showDetail
				this.$api.noteQueDetail(this.questionWithNote.id)
					.then(res => {
						console.log('题目详情', res)
						that.queDetail = res.values
					})

			},
			updateEditorText(e) {
				// 从子组件获取输入框输入内容
				console.log(e)
				this.editorText = e.detail.value
			},
			// deleteBtnFunc(cardIndex) {
			// 	uni.showToast({
			// 		title: '删除',
			// 		icon: 'none'
			// 	})
			// },
			getId(e) {
				console.log(e.currentTarget.id);
			},
		},
		computed:{
			noteId() {
				return "editor" + this.questionWithNote.id // 注意 id 要唯一！！
			}
		}
	}
</script>

<style lang="scss">
	.noteCard {
		box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.1);
		margin: 10rpx 20rpx;
		border-radius: 15upx;
		padding: 0 30upx;
		width: 710rpx;

		.noteTop {
			display: flex;
			// justify-content: space-between;
			flex-direction: column;
			// align-items: flex-start;
			padding: 15rpx 0 0 0;
			border-bottom: #d9d9d9 1px dashed;

			.topTitle {
				// font-weight: bold;
				font-size: 28rpx;
				color: $font-color-ps;
			}
		}

		.mainContent {
			// height: 100rpx;
			padding: 20rpx 0 10rpx 0;
			border-bottom: #d9d9d9 1px dashed;
			font-size: 28rpx;
			// color: #9e9e9e;
			line-height: 40upx;
			overflow: scroll;
			font-weight:bold;
		}

		.bottom {
			padding: 10upx 0;
			display: flex;
			justify-content: space-between;
			color: $font-color-ps;

			.funcBtn {
				margin-right: 10rpx;
				color: "#7f878c";
				font-size: 36rpx;
			}
		}


	}

	.QuesModal {
		padding: 24rpx;
	}
</style>
